//
//  HMNetWorking.swift
//  swift微博项目
//
//  Created by huodian on 16/9/26.
//  Copyright © 2016年 huodian. All rights reserved.
//

import UIKit

import AFNetworking

enum HMMethod {
    case GET
    case POST
}

class HMNetWorking: AFHTTPSessionManager {

    
    static let shareNetWorking:HMNetWorking = {
        
        let share = HMNetWorking()
        
        share.responseSerializer.acceptableContentTypes?.insert("text/html")
        
        share.responseSerializer.acceptableContentTypes?.insert("text/plain")
        
        
        return share
   
    }()
    
    func requset(method:HMMethod,url:String,parameters:Any?,finish:@escaping (Any?,Error?)->()) {
        
        let succed = { (task :URLSessionDataTask, responsedObject:Any?) in
            
            finish(responsedObject,nil)
            
        }
        
        
        let fause = { (task :URLSessionDataTask?, error:Error) in
            
            print("这个地方错了吗",error)
            
            finish(nil,error)
            
            
        }
        
        if method == .GET{
            
            get(url, parameters: parameters, progress: nil, success: succed, failure: fause)
            
            
        }else //if method == .POST
        {
            
            post(url, parameters: parameters, progress: nil, success: succed, failure: fause)
            
            
        }
        
        
        
    }
    
}
